home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7735 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.5 KB

  1. Path: sundog.tiac.net!ceylon!news
  2. From: Brenda <g051286>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Date: 28 Feb 1996 16:01:48 GMT
  6. Organization: GTE Laboratories Incorporated
  7. Message-ID: <4h1u9d$sqq@ceylon.gte.com>
  8. References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu> <4gtab6$acb@ceylon.gte.com> <313318b8.53776146@nntp.ix.netcom.com>
  9. NNTP-Posting-Host: 138.83.53.101
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.05 9000/712)
  14. X-URL: news://132.197.8.2/313318b8.53776146@nntp.ix.netcom.com
  15.  
  16. miker3@ix.netcom.com (Mike Rubenstein) wrote:
  17. >Brenda <g051286> wrote:
  18. >
  19. >> schlein@umbc.edu (Jonas J. Schlein) wrote:
  20. >> >Abu Wawda <wawda@alcor.usc.edu> wrote:
  21. >> >|> I'm having trouble understanding what the address of a static array
  22. >> >|> is.
  23. >> >
  24. >> >I'm having trouble understanding why it matters? You almost never use the
  25. >> >address of an array directly unless doing something tricky with pointers
  26. >> >or with particular dimensions of a multiple dimensional array.
  27. >> >
  28. >> >|> For example, if I declare a variable called myarray as:
  29. >> >|>     char myarray[10];
  30. >> >|> then what could &myarray possibly mean? myarray is not a pointer, so
  31. >> >|> &myarray could not possibly be the address of the variable myarray
  32. >> >|> (like it would be if I did char* myarray and then asked for &myarray).
  33. >> >
  34. >> >Yes it could and yes it is...'myarray' is not a pointer, but &myarray is
  35. >> >a pointer to 'myarray'.
  36. >> 
  37. >> Um, that's not correct.  myarray is DEFINITELY a pointer!  As declared above,
  38. >> it is a constant pointer to 10 contiguous char datatypes.  myarray is an
  39. >> ADDRESS whereas *(myarray + 5) or myarray[5] is the 6th element in the array.
  40. >> The difference between an array and something like "char *p=myarray", is that
  41. >> you can say p++, but you can't say myarray++.  You shouldn't say &myarray
  42. >> either because myarray is a constant, but I read that on some compilers
  43. >> scanf ignores the dereferencing and does not bother to warn you.
  44. >
  45. >NO. NO. NO.  Where do people get this idea that arrays are pointers.
  46. >Arrays are arrays and pointers are pointers.  In many, but not all,
  47. >situations an array is converted to a pointer.  There are exceptions.
  48. >For example sizeof myarray is 10 but sizeof p is almost certainly not
  49. >10.
  50. >
  51. >Why shouldn't you say &myarray.  It's perfectly legal C and any
  52. >compiler that does not accept it is broken.  &myarray is a pointer to
  53. >an array of 10 char.
  54. >
  55. >
  56. >Michael M Rubenstein
  57.  
  58. What is the definition of a pointer?  I have always been taught that a
  59. pointer is simply an address in memory, and an array name (i.e. myarray)
  60. is simply a CONSTANT address.  I don't think this statement is all that
  61. radical.  Of course there are differences between arrays and pointers
  62. due to the fact that an array is a CONSTANT address and a pointer is a
  63. VARIABLE address.  And the reason I said you shouldn't (note shouldn't
  64. not couldn't) say &myarray is:
  65.  
  66. ==================================================
  67. (from "A Book On C", Kelley & Pohl, pg 200)
  68. Constructs not to be pointed at:
  69. 1. Do not point at constants. (&3)
  70. 2. Do not point at arrays; an array name is a constant. (int a[77]; &a)
  71. 3. Do not point at ordinary expressions &(k + 99)
  72. 4. Do not point at register variables. (register v; &v)
  73. The address operator can be applied to variables and array elements.
  74. ===================================================
  75.  
  76. So again I say, myarray is DEFINITELY a pointer (i.e. address in memory).
  77.  
  78.